package net.siufung.market.base.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.siufung.core.result.Result;
import net.siufung.market.base.user.controller.assembler.UserRoleAssembler;
import net.siufung.market.base.user.controller.model.vo.UserRoleVo;
import net.siufung.market.base.user.mapper.IUserRoleMapper;
import net.siufung.market.base.user.mapper.entity.UserRole;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统角色权限 前端控制器
 *
 * @author 陈建峰
 * @since 2022-07-05 16:14:50
 */

/**
 * 用户角色
 * @author 陈建峰
 * @since 2022/8/4 3:49 下午
 */
@Api(tags = "角色权限管理")
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/sys/user/role")
public class UserRoleController {

    private final IUserRoleMapper userRoleMapper;

    /**
     * 获取 系统用户角色列表
     * @param userId 属性
     * @return Result<List<UserRoleVo>>
     * */
    @ApiOperation(value = "获取系统角色权限列表")
    @GetMapping(value = "/list")
    public Result<List<UserRoleVo>> list(@RequestParam Integer userId) {
        return Result.ok(
                UserRoleAssembler.fromList(userRoleMapper.selectList(
                        new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, userId))));
    }
}
